import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'Login/agreement.dart';
import 'Login/password.dart';
import 'Login/sms.dart';
import 'Login/bottom.dart';
import 'package:fluwx/fluwx.dart';
//import 'package:fluwx/fluwx.dart' as fluwx;

class LoginPage extends StatefulWidget {
  LoginPage({Key key}) : super(key: key);
  _LoginPageState createState() => _LoginPageState();
}

class _LoginPageState extends State<LoginPage>
    with SingleTickerProviderStateMixin {
  String _loginType;
  String username = '';
  String password = '';
  @override
  void initState() {
    super.initState();
    _initFluwx();
    setState(() {
      _loginType = 'password';
    });
  }

  _initFluwx() async {
    await registerWxApi(
        appId: "wx25a6cf2c50ee32b1",
        doOnAndroid: true,
        doOnIOS: true,
        universalLink: "https://jujij.com/");
    var result = await isWeChatInstalled;
    print("is installed $result");
  }

  //监听登录页面销毁的事件
  dispose() {
    super.dispose();
//    eventBus.fire(new UserEvent('登录成功...'));
  }

  Widget switchLoginWay() {
    return Container(
      height: 30.h,
//      padding: EdgeInsets.only(left: 50, right: 50),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.center,
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          InkWell(
            onTap: () {
              setState(() {
                _loginType = 'password';
              });
            },
            child: Container(
              padding: EdgeInsets.all(10),
              child: Text('账号密码登录',
                  style: TextStyle(
                      fontSize: 30.sp,
                      color: _loginType == 'password'
                          ? Colors.red
                          : Colors.black)),
            ),
          ),
          Container(
            margin: EdgeInsets.only(left: 20, right: 20),
            child: SizedBox(
              width: 2,
              height: 30.h,
              child: Container(
//              margin: EdgeInsets.only(left:20,right:20),
                  color: Colors.black),
            ),
          ),
          InkWell(
            onTap: () {
              setState(() {
                _loginType = 'sms';
              });
            },
            child: Container(
              padding: EdgeInsets.all(10),
              child: Text('短信验证码登录',
                  style: TextStyle(
                      fontSize: 30.sp,
                      color: _loginType == 'sms' ? Colors.red : Colors.black)),
            ),
          ),
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(context, width: 750, height: 1334);
    return Scaffold(
      backgroundColor: Colors.white,
        resizeToAvoidBottomPadding: false,
        appBar: AppBar(
          title: Text("聚集集登录",
            style: TextStyle(
                fontSize: 30.sp,
                fontWeight: FontWeight.bold),),
          centerTitle: true,
        ),
        body: Column(
          children: [
            Center(
              child: Container(
                  margin: EdgeInsets.only(top: 30),
                  height: 160.w,
                  width: 650.w,
                  child: switchLoginWay()),
            ),
//            AnimatedSize(
//              duration: Duration(milliseconds: 1000),
//              vsync: this,
//
//              child: Container(
//                color:Colors.green,
//                width:290,
//                height:100
//              ),
//            ),
            Container(
//              height: 550.h,
              width: 700.w,
              padding: EdgeInsets.all(20.w),
              child: _loginType == 'password' ? PasswordLogin() : SmsLogin(),
            ),
            LoginBottom(),
//            Agreement()
          ],
        ));
  }
}
